package com.czx.controller;

import com.czx.entity.User;
import com.czx.common.security.UserTokenThreadLocal;
import com.czx.service.UserService;
import com.czx.service.fileUploadService;
import com.czx.common.utils.R;
import com.czx.vo.UserToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;



@Controller
public class fileUploadController {
    @Autowired
    private fileUploadService  fileUploadService;
    @Autowired
    private UserService userService;
    @RequestMapping("/fileUpload")
    public String fileUpload(MultipartFile file){
        UserToken userToken = UserTokenThreadLocal.get();
        User user = userToken.getUser();
        R r = fileUploadService.upload(file, user);
        if(r.get("code").equals(200)){
            return "redirect:/";
        }
        return "error/500.html";
    }
}
